const Sequelize = require("sequelize");
const config = require("../config"); // 引入配置文件

const dbConfig = config.mysql;
console.log("数据库配置信息:", dbConfig);

const sequelize = new Sequelize(
  dbConfig.database,
  dbConfig.user,
  dbConfig.password,
  {
    host: dbConfig.host,
    dialect: "mysql",
    pool: {
      max: config.pool.max,
      min: config.pool.min,
      acquire: config.pool.acquire,
      idle: config.pool.idle,
    },
    define: {
      charset: "utf8mb4",
      collate: "utf8mb4_unicode_ci",
    },
    logging: console.log,
  }
);

sequelize
  .authenticate()
  .then(() => {
    console.log("数据库连接成功！");
  })
  .catch((err) => {
    console.error("无法连接到数据库:", err);
  });

module.exports = sequelize; // 确保导出 sequelize 实例
